package utils;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.example.administrator.test.passengernearcar.Constant;
import com.example.administrator.test.passengernearcar.PostRoute;
import com.example.administrator.test.passengernearcar.SubmitOrderBean;
import com.example.administrator.test.passengernearcar.TurnOrderBean;
import com.example.administrator.test.passengernearcar.TurnSubmitOrderBean;
import com.google.gson.Gson;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.GsonConverterFactory;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by Administrator on 2016/12/30.
 */
public class SubmitOrder {
    Handler mHandler=new Handler();

    public static void submitOrder(String token, String locPlaceName, String locPlaceLng, String locPlaceLat, String endPlaceName,
                                   final String endPlaceLng, final String endPlaceLat, String locCarType){
        SubmitOrderBean submitOrderBean=new SubmitOrderBean();
        submitOrderBean=initData(submitOrderBean,token,locPlaceName,locPlaceLng,locPlaceLat,endPlaceName,endPlaceLng,endPlaceLat,locCarType);
        Gson gson=new Gson();
        String route=gson.toJson(submitOrderBean);
        Log.i("tag",route+"----------------------------");
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        PostRoute postRoute=retrofit.create(PostRoute.class);
        RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),route);
        Call<TurnSubmitOrderBean> call=postRoute.SubmitOrder(body);
        call.enqueue(new Callback<TurnSubmitOrderBean>() {
            @Override
            public void onResponse(Call<TurnSubmitOrderBean> call, Response<TurnSubmitOrderBean> response) {
                TurnSubmitOrderBean turnSubmitOrderBean=new TurnSubmitOrderBean();
                String resultCode=turnSubmitOrderBean.getResultCode();
                String description=turnSubmitOrderBean.getDescription();
                String orderNumber=turnSubmitOrderBean.getOrderNumber();
                String driverNumber=turnSubmitOrderBean.getDriverNumber();
            }

            @Override
            public void onFailure(Call<TurnSubmitOrderBean> call, Throwable t) {

            }
        });
    }

    private static SubmitOrderBean initData(SubmitOrderBean submitOrderBean,String token,String locPlaceName, String locPlaceLng,
                                          String locPlaceLat,String endPlaceName, String endPlaceLng,String endPlaceLat,String locCarType){
        submitOrderBean.setOperType("2006");
        submitOrderBean.setToken(token);
        submitOrderBean.setLocPlaceName(locPlaceName);
        submitOrderBean.setLocPlaceLng(locPlaceLng);
        submitOrderBean.setLocPlaceLat(locPlaceLat);
        submitOrderBean.setEndPlaceName(endPlaceName);
        submitOrderBean.setEndPlaceLng(endPlaceLng);
        submitOrderBean.setEndPlaceLat(endPlaceLat);
        submitOrderBean.setLocCarType(locCarType);
        return submitOrderBean ;
    }
}


